package com.donquijote.spring6.dao.impl;

import com.donquijote.spring6.dao.ActDao;
import com.donquijote.spring6.pojo.ActBean;
import jakarta.annotation.Resource;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author 421527548@qq.com
 * @version V1.0
 * @title
 * @description
 * @date 2022-12-29 11:07
 */
@Repository("actDaoImpl")
public class ActDaoImpl implements ActDao {

    @Resource(name = "jdbcTemplate")
    private JdbcTemplate jdbcTemplate;
    @Override
    public Double selectBalance(String actNo) {
        ActBean actBean = jdbcTemplate.
                queryForObject(
                        "select actno,balance from t_act  where actno = ?",
                        new BeanPropertyRowMapper<>(ActBean.class),
                        actNo);

        return actBean.getBalance();
    }

    @Override
    public int updateBalance(String actNo ,Double money) {
        int update = jdbcTemplate.update(
                "update t_act set balance=balance + ? where actNo = ?",
                money,actNo);
        return update;
    }
}
